<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<script type="text/javascript">
get_check=function(){
	var ids = '';
	$("#list").find("input[type='checkbox']").each(function(){
		if ($(this).is(":checked"))
		{
			if (ids)
			{
				ids += ',';
			}
			ids += $(this).val();
		}
	});
	return ids;	
};
$(function(){
	$(".datepicker").datepicker({dateFormat:'yy-mm-dd',changeMonth:true});
	$(".detail").colorbox({width:"90%", height:"80%", iframe:true});
	$("#check_all").click(function(){
		if ($(this).is(":checked"))
		{
			$("#list input[type='checkbox']").attr("checked", true);
		}
		else
		{
			$("#list input[type='checkbox']").attr("checked", false);
		}
	});
	$(".audit").click(function(){
		if (!confirm("确定审核入库？"))
		{
			return false;
		}
	});
	$("#audit_btn").click(function(){
		var ids = get_check();
		if (!confirm("确定审核入库？"))
		{
			return false;
		}
		if (! ids)
		{
			alert("请选择采购单");
			return false;
		}
		window.location.href = "<?=url('Storage::Purchase/Audit', array(Q::ini('unique_token_name')=>Helper_BSS_Normal::genToken()))?>&ids=" + ids;
	});
	$("#back_btn").click(function(){
		var ids = get_check();
		if (!confirm("确定返回已采购？"))
		{
			return false;
		}
		if (! ids)
		{
			alert("请选择采购单");
			return false;
		}
		window.location.href = "<?=url('Storage::Purchase/ReturnPurchased', array(Q::ini('unique_token_name')=>Helper_BSS_Normal::genToken()))?>&ids=" + ids;
	});
	$("#print_btn").click(function(){
		var ids = get_check();
		if (! ids)
		{
			alert("请选择采购单");
			return false;
		}
		window.open("<?=url('Storage::Purchase/PrintReceivingTable')?>&ids=" + ids);
	});
	$("#print_product_barcode_btn").click(function(){
		var ids = get_check();
		if (! ids)
		{
			alert("请选择采购单");
			return false;
		}
		window.open("<?=url('Storage::Purchase/PrintProductBarcode')?>&ids=" + ids);
	});
});
</script>
<fieldset><legend>查询条件</legend>
<form action="" method="get">
<? include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
	<tr>
		<th>采购日期</th>
		<td>
			<input type="text" name="begin_purchase_time" class="datepicker" value="<?=isset($_GET['begin_purchase_time'])?$_GET['begin_purchase_time']:''?>" /> to 
			<input type="text" name="end_purchase_time" class="datepicker" value="<?=isset($_GET['end_purchase_time'])?$_GET['end_purchase_time']:''?>" />
		</td>
	</tr>
	<tr>
		<th>采购单号</th>
		<td><input type="text" name="purchase_order_number" value="<?=isset($_GET['purchase_order_number']) ? $_GET['purchase_order_number'] : '' ?>" /></td>
	</tr>
	<tr>
		<th>产品编号</th>
		<td><input type="text" name="product_basic_number" value="<?=isset($_GET['product_basic_number']) ? $_GET['product_basic_number'] : '' ?>" /></td>
	</tr>
	<tr>
		<th>采购人员</th>
		<td>
			<select name="purchase_user_id">
			<option value="0">请选择...</option>
		  	<? foreach($user as $u):?>
		  	<option value="<?=$u['id'];?>" <? if(isset($_GET['purchase_user_id']) and ($_GET['purchase_user_id'] == $u['id'])):?>selected="selected"<? endif;?>><?=$u['name'];?></option>
		  	<? endforeach;?>
		  	</select>
		</td>
	</tr>
	<tr>
		<th>结款类型</th>
		<td>
			<select name="purchase_order_payment_type">
				<option value="">请选择..</option>
				<? foreach (Q::ini('custom_flag/purchase_order_payment_type') as $pt):?>
				<option value="<?=$pt['value']?>" <?if (isset($_GET['purchase_order_payment_type'])&&$_GET['purchase_order_payment_type']== $pt['value'])echo "selected='selected'" ?>><?=$pt['name']?></option>
				<? endforeach;?>
				</select>
		</td>
	</tr>
	<tr>
		<th>仓库</th>
		<td>
			<select name="warehouse_id">
				<option value="">请选择..</option>
				<?foreach ($warehouse as $w):?>
				<option value="<?=$w['id']?>" <?if (isset($_GET['warehouse_id'])&&$_GET['warehouse_id']==$w['id'])echo "selected='selected'"?>><?=$w['name']?></option>
				<?endforeach;?>
			</select>
		</td>
	</tr>
	<tr>
		<th>筛选条件</th>
		<td>
			<label><input type="checkbox" name="timeout_purchase_order" value="1" <?if (!empty($_GET['timeout_purchase_order']))echo "checked='checked'"?>/> 超时采购单</label>
		</td>
	</tr>
	<tr>
		<th>状态</th>
		<td>
			<label><input type="checkbox" name="purchase_order_status[<?=Q::ini('custom_flag/purchase_order_status/arrived/value')?>]" value="<?=Q::ini('custom_flag/purchase_order_status/arrived/value')?>" <?if (isset($_GET['purchase_order_status']) && array_key_exists(Q::ini('custom_flag/purchase_order_status/arrived/value'), $_GET['purchase_order_status'])) echo "checked='checked'"?> /> <?=Q::ini('custom_flag/purchase_order_status/arrived/name')?></label>
			<label><input type="checkbox" name="purchase_order_status[<?=Q::ini('custom_flag/purchase_order_status/partial_storaged/value')?>]" value="<?=Q::ini('custom_flag/purchase_order_status/partial_storaged/value')?>" <?if (isset($_GET['purchase_order_status']) && array_key_exists(Q::ini('custom_flag/purchase_order_status/partial_storaged/value'), $_GET['purchase_order_status'])) echo "checked='checked'"?> /> <?=Q::ini('custom_flag/purchase_order_status/partial_storaged/name')?></label>
			<label><input type="checkbox" name="purchase_order_status[<?=Q::ini('custom_flag/purchase_order_status/storaged/value')?>]" value="<?=Q::ini('custom_flag/purchase_order_status/storaged/value')?>" <?if (isset($_GET['purchase_order_status']) && array_key_exists(Q::ini('custom_flag/purchase_order_status/storaged/value'), $_GET['purchase_order_status'])) echo "checked='checked'"?> /> <?=Q::ini('custom_flag/purchase_order_status/storaged/name')?></label>
		</td>
	</tr>
	<tr>
		<td></td>
		<td><input type="submit" value="查询" class="button" /></td>
	</tr>
</table>
</form>
</fieldset>
<table width="100%" class="list_table" id="list">
	<tr>
		<th width="30"></th>
		<th width="80">采购单号</th>
		<th width="60">所属仓库</th>
		<th width="80">结款类型</th>
		<th width="100">采购日期</th>
		<th width="100">完成日期</th>
		<th width="100">到仓日期</th>
		<th width="100">入库日期</th>
		<th width="60">实际总价</th>
		<th width="50">采购人</th>
		<th width="50">状态</th>
		<th width="150">操作</th>
	</tr>
	<?foreach ($purchase_order as $p):?>
	<tr>
		<td><input type="checkbox" value="<?=$p['id']?>" /></td>
		<td><a class="detail" href="<?=url('Storage::Purchase/Detail', array('id'=>$p['id'], 'show_all' => 0, 'operate' => true))?>" ><?=$p['number']?></a></td>
		<td><?=($p['warehouse_name'] == '广州仓') ? $p['warehouse_name'] : '<span class="red">' . $p['warehouse_name'] . '</span>'?></td>
		<td><?=Helper_BSS_Normal::getIniOne('purchase_order_payment_type','value',$p['payment_type'],'name')?></td>
		<td title="<?='采购时间：' . $p['purchase_time'] . ' ' . $p['purchase_user_name']?>"><?=substr($p['purchase_time'], 0, 10)?></td>
		<td title="<?='完成时间：' . $p['complete_time'] . ' ' . $p['complete_user_name']?>"><?=substr($p['complete_time'], 0, 10)?></td>
		<td title="<?='到仓时间：' . $p['arrive_time'] . ' ' . $p['arrive_user_name']?>"><?=substr($p['arrive_time'], 0, 10)?></td>
		<td title="<?='入库时间：' . $p['storage_audit_time'] . ' ' . $p['storage_user_name']?>"><?=substr($p['storage_audit_time'], 0, 10)?></td>
		<td><?=sprintf('%.2f', $p['actual_amount'])?></td>
		<td><?=$p['purchase_user_name']?></td>
		<td><?=Helper_BSS_Normal::getIniOne('purchase_order_status', 'value', $p['status'], 'name')?></td>
		<td>
			<?if ($p['status'] == Q::ini('custom_flag/purchase_order_status/arrived/value') || $p['status'] == Q::ini('custom_flag/purchase_order_status/partial_storaged/value')): ?>
			<a href="<?=url('Storage::Purchase/Audit', array('ids'=>$p['id']))?>" class="audit">审核入库</a>
			<?else:?>
			<font color="#aaaaaa">审核入库</font>
			<?endif;?>
			<a target="_blank" href="<?=url('Storage::Purchase/PrintReceivingTable', array('ids'=>$p['id']))?>">打印收货单</a>
			<a target="_blank" href="<?=url('Storage::Purchase/PrintProductBarcode', array('ids'=>$p['id']))?>">打印条形码</a>
			<?if ($p['status'] == Q::ini('custom_flag/purchase_order_status/arrived/value')):?>
			<a onclick="if(!confirm('确定返回已采购？')) return false;" href="<?=url('Storage::Purchase/ReturnPurchased', array('ids'=>$p['id'], Q::ini('unique_token_name')=>Helper_BSS_Normal::genToken()))?>">返回已采购</a>
			<?endif;?>
		</td>
	</tr>
	<?endforeach;?>
</table>
<?=$page?>
<table class="list_table">
<tr>
	<td><label><input type="checkbox" id="check_all" /> 全选</label></td>
	<td>
		按勾选：
		<input type="button" value="返回已采购" class="button" id="back_btn" /> |
		<input type="button" value="合并入库" class="button" id="audit_btn" /> |
		<input type="button" value="打印收货单" class="button" id="print_btn" /> | 
		<input type="button" value="打印条形码" class="button" id="print_product_barcode_btn" />
	</td>
</tr>
</table>
<?php $this->_endblock(); ?>